var usernameEle = document.getElementsByClassName('username')[0];
var passwordEle = document.getElementsByClassName('password')[0];
var errorName = document.getElementsByClassName('error_name')[0];
var errorPwd = document.getElementsByClassName('error_pwd')[0];
var btnEle = document.getElementsByClassName('btn')[0];

var usernameflag = false;
var passwordflag = false;

usernameEle.onblur = checkUsername;
passwordEle.onblur = checkPassword;
btnEle.onclick = function(){
    alert('提交')
}
function checkUsername(e){
    var value = e.target.value;
    var reg = /^[0-9a-zA-Z_-]{4,16}$/
    usernameflag = reg.test(value);
    if(reg.test(value)){
        errorName.innerText = ''

        errorName.style.dispaly = 'none';
    }else{
        errorName.style.dispaly = 'flex'
        errorName.innerText = '用户名输入错误'
    }
    controlBtnDisabled();
}
function checkPassword(e){
    var value = e.target.value;
    var reg = /^[0-9a-zA-Z_]{5,18}$/
   passwordflag = reg.test(value);
    if(reg.test(value)){
        errorPwd.style.dispaly = 'none';
    }else{
        errorPwd.style.dispaly = 'flex'
        errorPwd.innerText = '密码输入错误'
    }
    controlBtnDisabled();
}
function controlBtnDisabled(){
    btnEle.disabled = !(passwordflag && usernameflag);
    console.log('usernameflag',usernameflag);
console.log('passwordflag',passwordflag);
console.log(!passwordflag && !usernameflag);
}

